<?php
/**
 * @package html
 */
/**
 * Toolkit for easy generation of html code.
 */
class HtmlHelper {
	/**
	 * Provide imlicit filing of html tag input - checkbox
	 * 
	 * @param $name - value of name attribute
	 * @param $uncheckedValue - optional value which indicates, that checkbox should be unchecked
	 * @return - attribute name and checked properly filled
	 */
	static function selectedInputCheckboxWithAttr($name, $unCheckedValue = null) {
		if (@isset(self::$valuesToInit[$name]) && self::$valuesToInit[$name] != $unCheckedValue) {
			return "name=\"$name\" checked=\"checked\"";
		} else {
			return "name=\"$name\"";
		}
	}
	/**
	 * Provide imlicit filing of html tag option (which should be in an select)
	 * 
	 * @param $name - value of name attribute of parent tag select
	 * @param $value - value of an option
	 * @return - attribute selected and value properly filled
	 */
	static function selectedSelectWithAttr($name, $value) {
		if (@self::$valuesToInit[$name] == $value) {
			return "value=\"$value\" selected=\"selected\"";
		}
		return "value=\"$value\"";
	}
	
	/**
	 * Provide implicit filing of html tag input - radio.
	 * Content of $_REQUEST[$name] will be filled into attribute value.
	 * 
	 * @param $name - name attribute
	 * @param $value - value of the name
	 * @return - attributes name and value properly filled
	 */
	static function inputRadioValueWithAttr(string $name, $value) {
		if (@self::$valuesToInit[$name] == $value) {
			return "name=\"$name\" value=\"$value\" checked=\"checked\"";
		} else {
			return "name=\"$name\" value=\"$value\"";
		}
	}
	
	/**
	 * Provide implicit filing of html tag input - radio.
	 * Content of $_REQUEST[$name] will be filled into attribute value.
	 * 
	 * @param $name - value of the attribute 'name'
	 * @return - attributes name and value properly filled
	 */
	static function inputValueWithAttr(string $name) {
		if (@isset(self::$valuesToInit[$name])) {
			return "name=\"$name\" value=\"".self::$valuesToInit[$name]."\"";
		} else {
			return "name=\"$name\"";
		}
	}
	
	/**
	 * Simply return value for an attribute.
	 * @param string $name - attribute's name
	 * @return string - value
	 */
	static function attributeValue(string $name) {
		if (@isset(self::$valuesToInit[$name])) {
			return self::$valuesToInit[$name];
		} else {
			return "";
		}
	}
	
	/**
	 * @var array - stores form data in an array like $_REQUEST does
	 */
	static private $valuesToInit;
	
	/**
	 * Setter
	 * @param array $arr - set it
	 */
	static function setValuesToInit(array $arr) {
		self::$valuesToInit = $arr;
	}
	
	/**
	 * Getter
	 * @return array
	 */
	static function getValuesToInit() {
		return self::$valuesToInit;
	}
}
?>